package com.xingdata.jjxc.utils;

import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.xingdata.jjxc.enty.CarhudEntity;
import com.xingdata.jjxc.enty.ComAddressEntity;
import com.xingdata.jjxc.enty.UserEntity;
import com.yepublib.zxsec.Jni;

public class SP {

	// 写偏�?创建桌面logo
	public static void saveCreateLogo(Context context) {
		SharedPreferences sp = context.getSharedPreferences("create_logo",
				Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putString("createLogo", "1");
		edit.commit();
	}

	// 读偏�?创建桌面logo
	public static String getCreateLogo(Context context) {
		SharedPreferences sp = context.getSharedPreferences("create_logo",
				Context.MODE_PRIVATE);
		String createLoge = sp.getString("createLogo", "");
		return createLoge;
	}

	// 写用户信息偏�?
	public static void saveUserInfo(Context context, UserEntity user) {
		SharedPreferences sp = context.getSharedPreferences("user_info",
				Context.MODE_PRIVATE);
		SystemInfo.setUserInfo(user);
		if (user==null) {
			user=new UserEntity();
		}
		Editor edit = sp.edit();
		edit.putString("userid", user.getUserid());
		edit.putString("username", user.getUsername());
		edit.putString("mobile", user.getMobile());
		edit.putString("pw",Jni.Jni_encryptionStr(user.getPw(), user.getMobile()));
		Log.i("SP pw  ", user.getPw());
		edit.putString("head", user.getHead());
		edit.putString("email", user.getEmail());
		edit.putString("weixin", user.getWeixin());
		edit.putString("sina", user.getSina());
		edit.putString("qq", user.getQq());
		edit.commit();
	}

	// 取出用户信息
	public static UserEntity getUserInfo(Context context) {
		SharedPreferences sp = context.getSharedPreferences("user_info",
				Context.MODE_PRIVATE);
		UserEntity entity = new UserEntity();
		entity.setUsername(sp.getString("username", ""));
		entity.setHead(sp.getString("head", ""));
		entity.setEmail(sp.getString("email", ""));
		entity.setWeixin(sp.getString("weixin", ""));
		entity.setSina(sp.getString("sina", ""));
		entity.setQq(sp.getString("qq", ""));
		entity.setMobile(sp.getString("mobile", ""));
		entity.setPw(Jni.Jni_decryptionStr(sp.getString("pw", ""), entity.getMobile()));
		entity.setUserid(sp.getString("userid", ""));
		// UserEntity user = new UserEntity(userid, username, head, email,
		// weixin,
		// sina, qq);
		return entity;
	}

	// public static void saveMobileAndPassword(Context context, String phone,
	// String pwd, String autoLogin) {
	// SharedPreferences sp = context.getSharedPreferences("mb_and_pwd",
	// Context.MODE_PRIVATE);
	// Editor edit = sp.edit();
	// edit.putString("mb", phone);
	// edit.putString("pwd", pwd);
	// edit.putString("autoLogin", autoLogin); // autoLogin用于自动登录 : "" - 正常登录 |
	// // 0 - 自动登录
	// edit.commit();
	// }
	//
	// public static String[] getMobileAndPassword(Context context) {
	// String[] str = new String[3];
	// SharedPreferences sp = context.getSharedPreferences("mb_and_pwd",
	// Context.MODE_PRIVATE);
	// str[0] = sp.getString("mb", "");
	// str[1] = sp.getString("pwd", "");
	// str[2] = sp.getString("autoLogin", "");
	// return str;
	// }

	// 登录保存的hud信息
	public static void saveHudInfo(Context context, String carHudJson) {
		SharedPreferences sp = context.getSharedPreferences("car_hud",
				Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putString("carHudJson", carHudJson);
		edit.commit();
	}

	// 登录读取hud信息
	public static List<CarhudEntity> getHudInfo(Context context) {
		SharedPreferences sp = context.getSharedPreferences("car_hud",
				Context.MODE_PRIVATE);
		String carHudJson = sp.getString("carHudJson", "[]");
		return JUtils.getcarHudList(carHudJson);
	}

	// 常用地点保存
	public static void saveSite(Context context, String siteJson) {
		SharedPreferences sp = context.getSharedPreferences("site_info",
				Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putString("siteJson", siteJson);
		edit.commit();
	}

	// 常用地点获取
	public static List<ComAddressEntity> getSite(Context context) {
		SharedPreferences sp = context.getSharedPreferences("site_info",
				Context.MODE_PRIVATE);
		String siteJson = sp.getString("siteJson", "[]");
		return JUtils.getSiteList(siteJson);
	}

}
